package com.example.controller;

//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.Result;
import com.example.pojo.entity.Collection;
import com.example.service.CollectionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collection")
public class CollectionController {

    @Autowired
    CollectionService collectionService;

    /*
    * 新增用户
    * */
    @PostMapping("/add")
    public Result add(@RequestBody Collection collection){
        collectionService.insert(collection);
        return Result.success();
    }
/*
      修改用户
     */
    @PutMapping("/update")
    public Result update(@RequestBody Collection collection){
        collectionService.updateById(collection);
        return Result.success();
    }


/*
     删除用户
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        collectionService.removeById(id);
        return Result.success();
    }



     //批量删除用户

    @DeleteMapping("/delete/batch")
    public Result batchDelete(@RequestBody List<Integer> ids){
        collectionService.removeBatchByIds(ids);
        return Result.success();
    }


     // 查询所有用户

    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Collection> list = collectionService.list();
        return Result.success(list);
    }


    //根据ID查询用户

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Collection collection = collectionService.getById(id);
        return Result.success(collection);
    }


    // 分页查询用户

    @GetMapping("/selectByPage")
    public Result selectByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String name,
            @RequestParam(defaultValue = "") String type,
            @RequestParam(defaultValue = "") Integer showState) {
        PageInfo<Collection> pageInfo = collectionService.selectByPage(pageNum, pageSize, name, type, showState);
        return Result.success(pageInfo);
    }


}
